/*
 * Copyright (c) 2019. seven studio. @chengdu
 * seven studio in chengdu by lb
 * this project for snmp tool
 */

package com.xlx.openLink.threadtask.workservice;

import com.xlx.openLink.service.AlarmService;
import com.xlx.openLink.service.DeviceService;
import com.xlx.openLink.service.PortService;
import com.xlx.openLink.threadtask.workthread.SearchPortThread;
import com.xlx.openLink.uitls.Commuitls;
import com.xlx.openLink.vo.DevicePortVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class SearchPortService {

    @Autowired
    private DeviceService deviceService;
    @Autowired
    private PortService portService;
    @Autowired
    private AlarmService alarmService;

    public void SearchPortService(List<DevicePortVO> devicePortVOList) throws Exception {
        long start = System.currentTimeMillis();
        //创建线程池
        ExecutorService executorService = new ThreadPoolExecutor(20, 40, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue());

        //创建线程池
        List<List> listList = Commuitls.spList(devicePortVOList);
        for (List<DevicePortVO> list : listList) {
            executorService.execute(new SearchPortThread(list, deviceService, portService, alarmService));
        }
        executorService.shutdown();
        while (true) {
            if (executorService.isTerminated()) {
                log.info("执行成功----------------------");
                break;
            }
        }
        long time = System.currentTimeMillis() - start;
        double stime = (double) time / 1000;
        log.info("一次调用时间长度 " + stime + "s" + "------------------------------------------------------");


    }
}
